import java.awt.Color;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;

import java.awt.BasicStroke;
import org.jfree.chart.renderer.category.*;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.plot.*;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;


public class DataPlotter{
	public static void main(String[] argv) throws IOException{
		if(argv.length < 1){
			System.out.println("Usage: \n\tDataPlot <file1> <file2> ...");
			return;
		}
		XYSeriesCollection dataset = new XYSeriesCollection();
	   	for (int i = 0; i < argv.length; i++) {
			XYSeries series = new XYSeries(argv[i]);
			Scanner scan = new Scanner(new File(argv[i]));
			while(scan.hasNext()){
				series.add(scan.nextInt(), scan.nextDouble());
			}
			dataset.addSeries(series);
		}
				
		JFreeChart chart = ChartFactory.createXYLineChart("Score Chart", // Title
				"Nucleotide", // x-axis Label
				"Score", // y-axis Label
				dataset, // Dataset
				PlotOrientation.VERTICAL, // Plot Orientation
				true, // Show Legend
				false, // Use tooltips
				false // Configure chart to generate URLs?
			);
			
		XYItemRenderer cir = chart.getXYPlot().getRenderer();
		float lineWidth = 2f;
		BasicStroke stroke = new BasicStroke(lineWidth);
		for(int i=0;i<argv.length;i++)
			cir.setSeriesStroke(i, stroke);
		File fos = new File("output.jpg"); 
		ChartUtilities.saveChartAsJPEG(fos, 1.0f, chart, 1000, 800);
	//	chart.setBackgroundPaint(Color.white);
	//			//chart.getPlot().setBackgroundPaint(Color.WHITE);
	//					//ChartFrame frame = new ChartFrame("TSS Over Epochs", chart);
	//							//frame.pack();
	//									//frame.setVisible(true);		
	}}	
